﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace Platform.LanguageProcessing.Expressions
{
	public class SubjectExpression : GrammarExpression
	{

		public SubjectExpression( GrammarExpression subject )
			: this( new GrammarExpression[] { subject } )
		{ }

		public SubjectExpression( IEnumerable<GrammarExpression> subject )
			: base( GrammarClass.Subject )
		{
			this.Subject = subject;
			this.FillByPronouns();
		}

		private void FillByPronouns()
		{
			var pronouns = this.Subject.OfType<PronounExpression>();

			switch ( pronouns.Count() )
			{
				case 0:
					this.FillByPrepositions();
					break;

				case 1:
					var pro = pronouns.First();
					this.Gender = pro.Gender;

					//switch ( pro.Person )
					//{
					//    case Cardinality.None:
					//        break;
					//    case Cardinality.One:
					//        break;
					//    case Cardinality.MoreThanOne:
					//        break;
					//    default:
					//        break;
					//}

					break;

				// + de 1
				default:
					this.Gender = SubjectGender.Neutral;
					this.Person = PersonVerb.ThirdPlural;
					break;
			}
		}

		private void FillByPrepositions()
		{
			var prepos = this.Subject.OfType<PrepositionExpression>();

			if ( prepos.Count() == 0 )
			{
				Debug.WriteLine( "xx" );
				this.Person = PersonVerb.ThirdSingle;
			}
			else
			{
				// TODO : Verifica o número

				//switch ( prepos.BiggestCardinality() )
				switch ( prepos.First().Cardinality )
				{
					case Cardinality.MoreThanOne:
						this.Person = PersonVerb.ThirdPlural;
						break;

					case Cardinality.None:
					case Cardinality.JustOne:
					default:
						this.Gender = prepos.First().Gender;
						this.Person = PersonVerb.ThirdSingle;
						break;
				}
			}
		}

		public IEnumerable<GrammarExpression> Subject
		{ get; private set; }

		public PersonVerb Person
		{ get; private set; }


		public SubjectGender Gender
		{ get; set; }



	}
}
